package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Group;
import cn.kgc.springcloud.service.GroupService;
import cn.kgc.springcloud.vo.GroupVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author 课工场
 * @date 2025/1/17
 * @description
 */
@RestController
@RequestMapping("group")
public class GroupController {

    @Resource
    private GroupService groupService;

    @GetMapping
    public List<GroupVO> groupVOList(){
        return groupService.groupVOList();
    }

    @PostMapping
    public Boolean addGroup(@RequestBody Group group){
        group.setCreatedate(new Date());
        return groupService.save(group);
    }


    @GetMapping("{id}")
    public Group getGroup(@PathVariable("id") Integer id){
        LambdaQueryWrapper<Group> lambda = new QueryWrapper<Group>().lambda();
        lambda.select(Group::getId,Group::getName)
                .eq(Group::getId,id);

        Group group = groupService.getOne(lambda);
        return group;
    }
}
